package main

import (
    "bytes"
    "encoding/gob"
    "fmt"
)

type People struct {
    Name string
    Age  int
}

func main() {

    p := People{
        Name: "Jason Yin",
        Age:  18,
    }

    buf := bytes.Buffer{}

    encoder := gob.NewEncoder(&buf)

    err := encoder.Encode(p)
    if err != nil {
        fmt.Println("编码失败,错误原因: ", err)
        return
    }

    fmt.Println(string(buf.Bytes()))
}
